<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/9/29
  Time: 19:56
  To change this template use File | Settings | File Templates.
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/9/14
  Time: 20:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common/common.jsp"%>
<html>
<head>
    <title>Title</title>
    <style>
        .iframeClass{
            height:800px !important;
        }
    </style>
    <script type="text/javascript">
        $(function (){

        })
        $(function (){
            $('#table').bootstrapTable({
                url: '<%=path%>/tabRoute/getInfo',
                method: 'GET',                      //请求方式（*）
                toolbar: '#toolbar',              //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: true,                     //是否启用排序
                sortOrder: "asc",                       //排序方式
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
                pageSize: 3,                     //每页的记录行数（*）
                pageList: [2, 5, 10, 20],        //可供选择的每页的行数（*）
                search: true,                      //是否显示表格搜索
                // strictSearch: true,
                showColumns: true,                  //是否显示所有的列（选择显示的列）
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "eid",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                  //是否显示父子表
                local:"en_US",
                queryParams : function (params) {
                    //这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
                    var temp = {
                       rname:$('#rname').val(),
                    };
                    return temp;
                },
                columns: [{
                    checkbox: true,
                    visible: true                  //是否显示复选框
                },{
                    field: 'rid',
                    title: '线路号'
                }, {
                    field: 'rname',
                    title: '线路名称'
                }, {
                        field: 'price',
                        title: '价格'
                    },
                    {
                        field: 'routeintroduce',
                        title: '旅游线路介绍'
                    },
                    {
                        field: 'rflag',
                        title: '是否上下架',
                        formatter:function (value,row,index){
                            if (value == 1){
                                return "是";
                            }else {
                                return "否"
                            }
                        }
                    },
                    {
                        field: 'rdate',
                        title: '时间'
                    },
                    {
                        field: 'isthemetour',
                        title: '旅游主题'
                    },
                    {
                        field: 'count',
                        title: '统计'
                    },
                    {
                        field: 'cid',
                        title: '旅游线路分类',
                        formatter: function (value, row, index) {
                            var cid = row.cid;
                            var cname;
                            $.ajax({
                                url: "<%=path%>/tabRoute/getByCname/" + cid,
                                async: false,
                                success: function (result) {
                                    cname = result.cname;
                                },
                                error:function (result){
                                    console.log(result);
                                    alert("网络异常,请刷新");
                                }
                            })
                            return cname;
                        }
                    },
                    {
                        field: 'rimage',
                        title: '景区图片',
                        formatter:function (value,row,index){
                            return "<img src='<%=path%>/file/download?filename=" + value + "'width='100px' height='100px'>";
                        }

                    },
                    {
                        field: 'sid',
                        title: '商家ID',
                        formatter: function (value, row, index) {
                            var sid = row.sid;
                            var sname;
                            $.ajax({
                                url: "<%=path%>/tabRoute/getBySname/" + sid,
                                async: false,
                                success: function (result) {
                                    sname = result.sname;
                                },
                                error:function (result){
                                    console.log(result);
                                    alert("网络异常,请刷新");
                                }
                            })
                            return sname;
                        }
                    },
                    {
                        field: 'sourceid',
                        title: '资源ID'
                    },
                    {
                        field: 'rid',
                        title: '操作',
                        formatter: function (value, row, index) {
                            var id = value;
                            var result = "";
                            result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"DeleteByIds('" + id + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
                            result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"EditViewById('" + id + "')\" title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
                            return result;
                        }
                    }
                ]
            });
        })
        function EditViewById(id){
            BootstrapDialog.show({
                title: '修改',
                message: $('<div></div>').load('<%=path%>/tabRoute/toUpdate/' +id),
                closeable: true,
                buttons: [{
                    label: '确定',
                    action: function (dialog) {
                        $("[name=routeintroduce]").val(CKEDITOR.instances.content.getData())
                        $.ajax({
                            url: "<%=path%>/tabRoute/updateInfo",
                            type: "post",
                            dataType: "json",
                            data: $("#tabRoute_update_form").serialize(),
                            success: function (data) {
                                toastr.success("修改成功")
                                dialog.close();
                                getData()
                            },
                            error: function (data) {
                                toastr.error("修改失败")
                            }
                        })
                    }
                }]
            });
        }
        function DeleteByIds(id){
            if (confirm("有事好商量")){
                $.ajax({
                    url:"<%=path%>/tabRoute/deleteById",
                    data: {rid:id},
                    type: "get",
                    dataType: "json",
                    async:true,
                    success:function (result){
                        if (result){
                            toastr.success("删除成功")
                            getData();
                        }
                    },
                    error:function (result){
                        toastr.error("操作失败");
                    }
                })
            }

        }
        function toAdd() {
            BootstrapDialog.show({
                title: '增加',
                message: $('<div></div>').load('<%=path%>/tabRoute/toAdd'),
                closeable: true,
                buttons: [{
                    label: '确定',
                    action: function (dialog) {
                        $("[name=routeintroduce]").val(CKEDITOR.instances.content.getData())
                        $.ajax({
                            url: "<%=path%>/tabRoute/increase",
                            type: "post",
                            dataType: "json",
                            data: $("#tabRoute_add_form").serialize(),
                            success: function (data) {
                                toastr.success("增加成功")
                                dialog.close();
                                getData();
                            },
                            error: function (data) {
                                toastr.error("更新操作执行失败")
                            }
                        })
                    }
                }]
            });
        }
        function getData(){
            $("#table").bootstrapTable("refresh");
        }
    </script>
</head>
<body>
<div id="toolbar">
   <form class="form-inline" role="form" id="search_ch">
       <div class="form-group">
           <label class="sr-only" for="rname">名称</label>
           <input type="text" class="form-control" name="rname" id="rname" placeholder="请输入名称">
       </div>
            <input type="button" class="btn btn-default" value="搜索" onclick="getData()">
            <input type="button" class="btn-info" value="增加" onclick="toAdd()">
    </form>
</div>
<div id="table"></div>
</body>
</html>

